//
//  WhoCanSeeViewController.m
//  Cunli
//
//  Created by 湛亚 on 15/6/30.
//  Copyright (c) 2015年 lilubin. All rights reserved.
//

#import "WhoCanSeeViewController.h"
#import "WriteHelpViewController.h"

@interface WhoCanSeeViewController (){
    
    NSArray *chooseArray;
}

@end

@implementation WhoCanSeeViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.title=@"谁能看见";
    
    if (_type==1) {
        chooseArray=[[NSArray alloc]initWithObjects:@"村里人和家乡人",@"村里人",@"家乡人",nil];
    }else{
        chooseArray=[[NSArray alloc]initWithObjects:@"本村",@"本县",@"本市",nil];
    }
    
    _chooseTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
    _chooseTableView.dataSource=self;
    _chooseTableView.delegate=self;
    _chooseTableView.backgroundColor=[UIColor whiteColor];
    [_chooseTableView setEditing:NO animated:YES];
    if (_type==2) {
        _chooseTableView.rowHeight=54;
    }
    [self.view addSubview:_chooseTableView];
    
    UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(0, 0, 28, 28);
    [leftBtn setImage:[UIImage imageNamed:@"regback01"] forState:UIControlStateNormal];
    leftBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [leftBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarItem;
}

-(void)goBack{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 3;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdentifier=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if(!cell){
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }
    if (indexPath.row==_currentRange) {
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
    }
    
    cell.textLabel.text=[chooseArray objectAtIndex:indexPath.row];
    
    if (_type==2) {
        cell.detailTextLabel.text=[NSString stringWithFormat:@"仅%@的人可见",cell.textLabel.text];
        cell.detailTextLabel.textColor=[UIColor colorWithHexString:@"0x999999"];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    NSArray *arr=self.navigationController.viewControllers;
    WriteHelpViewController *writeVC= [arr objectAtIndex:[arr count]-2];
    writeVC.lastClick=indexPath.row;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
